package com.songcha.library_common.ui.dialog

import android.content.Context
import android.graphics.Color
import android.text.InputType
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.songcha.library_common.R
import com.songcha.library_common.ui.view.CustomContainerLayout
import com.songcha.library_common.ui.view.CustomContainerLayout_
import com.songcha.library_common.ui.view.CustomEditText
import com.songcha.library_common.util.ColorUtil
import com.songcha.library_common.util.dp2px

class InputDialog(context: Context) : CustomDialog(context) {
    private lateinit var mEdt:CustomEditText
    private var mInputType:Int?=null

    override fun hasView(): Boolean {
        return true
    }

    override fun getView(root:ViewGroup): View? {
        val ccl= CustomContainerLayout(context).apply {
            //setBorderWidth(1f.dp2px())
            //setBorderColor(ColorUtil.getResourceColor(context, R.color.primary))
            setBorder(ColorUtil.getResourceColor(context, R.color.primary),1f.dp2px())
            setRadius(20f.dp2px())
        }
        mEdt=CustomEditText(context)
        mEdt.setTextColor(Color.BLACK)
        mInputType?.let { mEdt.inputType=InputType.TYPE_CLASS_TEXT or it }
        val edtLp=ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        mEdt.layoutParams=edtLp
        mEdt.setPadding(10.dp2px(),0,10.dp2px(),0)
        ccl.addView(mEdt)

        val lp=FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,40.dp2px())

        //lp.topMargin=10.dp2px()
        lp.leftMargin=10.dp2px()
        lp.rightMargin=10.dp2px()
        lp.gravity=Gravity.CENTER_VERTICAL

        ccl.layoutParams=lp

        return ccl

    }

    fun getInput():String{
        return mEdt.text.toString()
    }

    fun setInputType(type:Int){
        //mEdt.inputType=type
        mInputType=type
    }

}